package com.itwn.controller;


import com.github.pagehelper.PageInfo;
import com.itwn.result.ResponseResult;
import com.itwn.service.CommentService;
import com.itwn.vo.CommentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.stream.events.Comment;
import java.util.List;

@RestController
@RequestMapping("comment")
@Api(value="评论操作")
public class CommentController {

    private CommentService commentService;


    @Autowired
    public CommentController(CommentService commentService) {
        this.commentService = commentService;

    }


    @GetMapping("/list")
    @ApiOperation(value="分页查询与条件模糊查询评论")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    paramType="query",name="pageNum",value="页码",
                    dataType="int",defaultValue = "1"),
            @ApiImplicitParam(
                    paramType="query",name="pageSize",value="每页多少内容",
                    dataType="int",defaultValue = "8"),
            @ApiImplicitParam(
                    paramType="query",name="inputByUser",value="用户输入的搜索关键字",
                    dataType="String"),
            @ApiImplicitParam(
                    paramType="query",name="select",value="用户选择的搜索类型（1评论内容/2电影名称/3用户名/4按全部条件匹配/0显示所有评论）",
                    dataType="String")
    })
    public ResponseResult<PageInfo<CommentVo>> showCommentList(@RequestParam(value="inputByUser",defaultValue=" ") String inputByUser,
                                                               @RequestParam(value="select",defaultValue="0") String select,
                                                               @RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                                               @RequestParam(value="pageSize",defaultValue = "8")Integer pageSize) {
        ResponseResult<PageInfo<CommentVo>> result = new ResponseResult<>();
        System.out.println("inputByUser--->"+inputByUser);
        System.out.println("select--->"+select);
        try{
            PageInfo<CommentVo> pageInfo = commentService.showAllComments(pageSize,pageNum,inputByUser,select);
            System.out.println("list---->"+pageInfo);
            result.setCode(200);//查询失败
            result.setMsg("查询成功");
            result.setData(pageInfo);

        }catch (Exception e){
            result.setCode(500);//查询失败
            result.setMsg("查询失败");
        }
        System.out.println("result--->"+result.getMsg());
        return result;
    }


    @PostMapping("/delete/{scoreId}")
    @ApiOperation(value="通过改变评论状态删除评论")
    public ResponseResult<Comment> deleteComment(@PathVariable("scoreId") Integer scoreId){
        ResponseResult<Comment> result = new ResponseResult<>();
        try{
            commentService.deleteComment(scoreId);
            result.setCode(200);
            result.setMsg("删除成功");
        }catch (Exception e){
            result.setCode(500);
            result.setMsg("删除失败");
        }

        return result;


}


}
